package br.com.peperoncino.controller.cardapio;

import java.math.BigDecimal;
import java.util.List;

import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.hibernate.internal.util.collections.CollectionHelper;

import br.com.peperoncino.entity.ItemCardapio;
import br.com.peperoncino.entity.TipoItem;

public class ItemCardapioTable {

	private final SimpleIntegerProperty rID;
	private final SimpleStringProperty rNome;
	private final SimpleStringProperty rDescricao;
	private final SimpleFloatProperty rValor;
	private final SimpleStringProperty rTipoItem;
	
	public ItemCardapioTable(Integer sID, String sNome, String sDescricao, Float sValor, String sTipoItem){
		this.rID = new SimpleIntegerProperty(sID);
		this.rNome = new SimpleStringProperty(sNome);
		this.rDescricao = new SimpleStringProperty(sDescricao);
		this.rValor = new SimpleFloatProperty(sValor);
		this.rTipoItem = new SimpleStringProperty(sTipoItem);
	}

	public Integer getRID() {
		return rID.get();
	}
	
	public void setRID(Integer v){
		rID.set(v);
	}
	
	public String getRNome() {
		return rNome.get();
	}
	
	public void setRName(String v){
		rNome.set(v);
	}
	
	public String getRDescricao() {
		return rDescricao.get();
	}
	
	public void setRDescricao(String v){
		rDescricao.set(v);
	}
	
	public Float getRValor() {
		return rValor.get();
	}
	
	public void setRValor(Float v){
		rValor.set(v);
	}

	public String getRTipoItem() {
		return rTipoItem.get();
	}
	
	public void setRTipoItem(String v){
		rTipoItem.set(v);
	}
	
   public ItemCardapio toItemCardapio(){
       return new ItemCardapio(
    		   getRID(),
               getRNome(),
               getRDescricao(),
               new BigDecimal(getRValor()),
               TipoItem.recuperaTipoItemPorDescricao(getRTipoItem())
       );
   }
   
   public static ObservableList<ItemCardapioTable> toCardapioTabela(List<ItemCardapio> itensCardapio){
	   
	   ObservableList<ItemCardapioTable> itensCardapioTable = FXCollections.observableArrayList();
	   
	   if(!CollectionHelper.isEmpty(itensCardapio)){
		   
		   for (ItemCardapio itemCardapio : itensCardapio) {
			   itensCardapioTable.add(new ItemCardapioTable(
					   itemCardapio.getId(), 
					   itemCardapio.getNome(), 
					   itemCardapio.getDescricao(), 
					   itemCardapio.getValor().floatValue(), 
					   itemCardapio.getTipoItem().toString()));
		   }
	   }
	   
	   return itensCardapioTable;
	}
}